#!/bin/bash
if [ $# -lt 2 ]; then
	echo "Los parametros 'comando' y 'mensaje' son obligatorios para el Log"
	exit 1
fi

if [ $1 = "Instalar_TP" ]; then
	if [ -z ${CONFDIR+x} ]; then
		echo "No esta seteado CONFDIR"
		exit 2	
	fi
	dir=$CONFDIR
	file=$dir/$1.log
else 
	variables=("LOGDIR" "LOGEXT" "LOGSIZE")
	for var in ${variables[*]}
	do	
		eval check='$'$var
		if [ -z ${check} ]; then
		echo "No esta seteada la variable $var"
		exit 2
		fi
	done
	dir=$LOGDIR
	file=$dir/$1$LOGEXT
	touch $file
	tam=$[ $(stat -c%s $file)/1024 ]
	if [ $tam -ge $LOGSIZE ]; then
		tail -50 $file > $file.tmp
		mv $file.tmp $file 
	fi
fi
if [ $# -eq 2 ]; then 
	message=$2
else
	tipo=$2
	message=$3
fi
total=$(date)-$(whoami)-$1-$tipo-$message
echo $total >> $file

